<template>
	<view class="body">
		<!-- <view class='body-title'>
			<image src="../../static/img/title1.png" mode="widthFix"></image>
		</view> -->
		
		
		<!-- <view class="body-form">
			<form>
				<view class="body-form-item">
					<view class="body-form-label">姓名</view>
					<view class="body-form-value">
						<input class="body-form-input" name="input" placeholder="请输入姓名" :value="userName" @input="getUserName" />
					</view>
				</view>
				<view class="body-form-item">
					<view class="body-form-label">手机号</view>
					<view class="body-form-value">
						<input class="body-form-input" name="input" placeholder="请输入手机号" :value="userMobile" @input="getUserMobile" />
					</view>
				</view>
				<view class="body-form-item">
					<view class="body-form-value2">
						<input class="body-form-input1" name="input" placeholder="请输入验证码" :value="code" @input="getCode"/>
					</view>
					<view class="body-form-code">
						<image :src="url" mode="widthFix" @click="getCodeImg"></image>
					</view>
				</view>
				<view>
					<button type="default" plain :loading="loading" @click="onSubmit" class='btn-next'>提交</button>
				</view>
			</form>
		</view>
		<view class='fixed-div' v-if="showLogo">
			<image src="../../static/img/logo.png" mode="widthFix"></image>
		</view>
 -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cardId: '',
				userName: '',
				userMobile: '',
				code: '',
				url: '',
				encryptedString: '',
				showLogo: false,
				loading: false,
			}
		},
		 onLoad(options) {
		    this.cardId = options.cardId; 
			let local = location.href;
			if (local.indexOf('192.168.1.107') > 0 || local.indexOf('d.1688iot.vip') > 0) {
				this.showLogo = true;
			}
			this.getCodeImg();
		},
		methods: {
			onSubmit(){
				if(this.userName==''){
					uni.showToast({
					   title: '请填写姓名',
					   icon: 'none',
					   duration: 2000		
					});
					return false
				}
				if(this.userName&&this.userName.length>10){
					uni.showToast({
					   title: '姓名长度不能超过10位',
					   icon: 'none',
					   duration: 2000		
					});
					return false
				}
				if(this.userMobile==''){
					uni.showToast({
					   title: '请填写手机号',
					   icon: 'none',
					   duration: 2000		
					});
					return false
				}
				let reg = /^(13[0-9]|14[5-9]|15[012356789]|166|17[0-8]|18[0-9]|19[8-9])[0-9]{8}$/;
				if(!reg.test(this.userMobile)){
					uni.showToast({
					   title: '请修改手机号',
					   icon: 'none',
					   duration: 2000		
					});
					return false
				}
				if(this.code==''){
					uni.showToast({
					   title: '请填写验证码',
					   icon: 'none',
					   duration: 2000		
					});
					return false
				}
				this.loading = true;
				this.$req.userRecharge('card/unlock/imgcheck',{
					id: this.cardId,				//cardId
					name: this.userName,			//姓名
					phone: this.userMobile,			//手机号
					imgCode: this.code,				//验证码
					uid: this.encryptedString,
				}).then(res=>{
					if(res.data){
						uni.showToast({
						   title: '绑定成功',
						   icon: 'success',
						   duration: 2000		
						});					
						this.userName = '';
						this.userMobile = '';
					}
				})
				this.code = '';
				this.encryptedString = '';
				this.url = '';
				this.getCodeImg()
				this.loading = false;
				
			},
			getCodeImg() {
				this.$req.sendCheck('/code/send/pictureCode/uid', {}).then(res => {
					if (res._result) {
						this.encryptedString = res.data
						this.url = '/api/oceanside-send-and-check/code/send/pictureCode/' + res.data
					}
				})
			},
			getUserName(e){
				this.userName = e.detail.value;  
			},
			getUserMobile(e){
				this.userMobile = e.detail.value; 
			},
			getCode(e){
				this.code = e.detail.value;  
			},
		}
	}
</script>

<style>
	.body {
		width: 90%;
		height: 90%;
		position: absolute;
		top: 0;
		left: 0;
		overflow-y: auto;
		/* background: linear-gradient(50deg, rgba(230, 240, 254, 0.6), rgba(183, 213, 255, 0.7), rgba(120, 168, 242, 0.8)); */
		background: #FFFFFF;
		padding: 5%;
	}

	.body-title {
		width: 80%;
		height: 30vw;
		position: relative;
		top: 0;
		left: 10%;
		line-height: 20vh;
	}

	.body-title image {
		width: 95%;
		height: auto;
		vertical-align: middle;
	}

	.fixed-div {
		width: 100%;
		height: 17vw;
		position: fixed;
		top: 70%;
		left: 0;
		z-index: 10;
	}

	.fixed-div image {
		width: 40%;
		height: auto;
		margin-left: 50%;
		opacity: 0.5;
	}
	/* 表单样式 */
	.body-form {
		width: 90%;
		height: auto;
		position: relative;
		top: 0;
		left: 0;
		margin: 40px 5%;
	}
	.body-form-item{
		width: 100%;
		height: auto;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 20px;
	}
	.body-form-label{
		width: 50px;
		height: 40px;
		position: relative;
		display: inline-block;
		text-align: center;
		line-height: 40px;
		font-size: 28upx;
		color: #555555;
	}
	.body-form-value{
		width: calc(90vw - 60px);
		height: 40px;
		position: relative;
		display: inline-flex;
		margin-left: 2vw;
	}
	.body-form-value2{
		width: 63vw;
		height: 40px;
		position: relative;
		display: inline-flex;
		align-items: center;
	}
	.body-form-input{
		width: 100%;
		height: 60upx;
		line-height: 80upx;
		outline: none;
		border: 1px solid white;
		background-color: white;
		border-radius: 5px;
		opacity: 0.5;
		padding: 10upx 20upx;
		font-size: 28upx;
	}
	.body-form-input1{
		width: 100%;
		height: 60upx;
		line-height: 80upx;
		outline: none;
		background-color: white;
		border-radius: 5px;
		opacity: 0.5;
		padding: 10upx 20upx;
		font-size: 28upx;
		border: 1px solid #78A8F2;
	}
	.body-form-code{
		width: 28vw;
		height: 51px;
		display: inline-flex;
		position: relative;
		justify-content: flex-end;
		align-items: center;
	}
	.body-form-code image{
		width: 100%;
		height: auto;
	}
		
	.btn-next{
		width: 80%;
		height: 80upx;
		line-height: 80upx;
		margin: 80px 10%;
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
		border: 1px solid #007AFF;
		color: #007AFF;
	}
	uni-button[type=default][plain] {
	    color: #007AFF;
	    border: 1px solid #007AFF;
	    background-color: rgba(0,0,0,0);
	}
</style>
